import React from 'react';
import ReactDOM from 'react-dom';
import { createStore } from 'redux';
import { counter } from './redux/reducers';

import App from './components/app';

const store = createStore(counter);

/**
 * console.log(store);
 * {
 *   //dispatch接受action对象作为参数
 *   dispatch: ƒ dispatch(action),
 *   subscribe: ƒ,
 *   //获取当前状态state的值
 *   getState: ƒ,
 *   replaceReducer: ƒ,
 *   @@observable: ƒ
 * }
 */

//当state发生更改时重新渲染页面
//当参数为函数的函数执行完毕后会调用subscribe
store.subscribe(render);

function render() {
  //将store对象传入app组件这样app组件可以用store的方法
  ReactDOM.render(<App store={store} />, document.getElementById('root'));
}

//首次页面渲染
render();
